const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const adminAuth = require('./middlewares/admin-auth');
require('dotenv').config();

//前台路由
const indexRouter = require('./routes/index');
const categoriesRouter = require('./routes/categories');
const coursesRouter = require('./routes/courses');

const usersRouter = require('./routes/users');
const adminArticleRouter = require('./routes/admin/Articles');
const adminCategoriesRouter = require('./routes/admin/Categories');
const adminSettingRouter = require('./routes/admin/Settings');
const adminUserRouter = require('./routes/admin/Users');
const adminCourseRouter = require('./routes/admin/Courses');
const adminChapterRouter = require('./routes/admin/Chapters');
const adminChartRouter = require('./routes/admin/Charts');
const adminAuthRouter = require('./routes/admin/Auths');

const decodeRouter = require('./routes/raydataWeb/decode');

const app = express() ;

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

//前台路由配置
app.use('/',indexRouter);
app.use('/categories',categoriesRouter);
app.use('/courses',coursesRouter);

app.use('/users', adminAuth,usersRouter);
app.use('/admin/articles', adminAuth,adminArticleRouter);
app.use('/admin/categories', adminAuth,adminCategoriesRouter);
app.use('/admin/settings', adminAuth,adminSettingRouter);
app.use('/admin/users', adminAuth,adminUserRouter);
app.use('/admin/courses', adminAuth,adminCourseRouter);
app.use('/admin/chapters', adminAuth,adminChapterRouter);
app.use('/admin/charts',adminAuth,adminChartRouter)
app.use('/admin/auths', adminAuthRouter);

app.use('/raydataWeb/decode',decodeRouter)

module.exports = app;
